package com.mjh.zhujianju.controller.agency;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.livew.framework.base.controller.BaseController;
import com.livew.framework.base.service.BaseService;
import com.livew.framework.exception.XTBusinessException;
import com.livew.framework.page.PagedResult;
import com.livew.framework.pojo.AjaxResult;
import com.mjh.zhujianju.model.agency.RemoveEO;
import com.mjh.zhujianju.service.agency.RemoveService;
import com.mjh.zhujianju.vo.agency.RemoveVO;

@Controller
@RequestMapping("agency/remove")
public class RemoveController extends BaseController<RemoveEO>{

	@Resource
	private RemoveService removeService;
	@Override
	protected BaseService<RemoveEO> getService() {
		
		return removeService;
	}
	
	
	@RequestMapping(value = "saveInfo", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult saveInfo(RemoveVO vo) {
		if (vo == null) {
			return AjaxResult.getResult(Boolean.FALSE, "参数错误");
		}
		try {
			removeService.saveInfo(vo);
		} catch (XTBusinessException e) {
			e.printStackTrace();
			return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
		}
		return AjaxResult.getResult(Boolean.TRUE, "保存成功");
	}

	@RequestMapping(value = "updateInfo", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult updateInfo(RemoveVO vo) {
		if (vo == null) {
			return AjaxResult.getResult(Boolean.FALSE, "参数错误");
		}
		try {
			removeService.updateInfo(vo);
		} catch (XTBusinessException e) {
			e.printStackTrace();
			return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
		}
		return AjaxResult.getResult(Boolean.TRUE, "保存成功");
	}

	/**
	 * 获取所有的组织机构
	 * 
	 * @Description:
	 * @return
	 * @author wt1293
	 * @date 2018年8月9日下午8:08:53
	 *
	 */
	@RequestMapping(value = "getPage", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult getPage(RemoveVO eo) {
		PagedResult<RemoveVO> list = removeService.getVOPage(eo);
		return AjaxResult.getResult(list);
	}

	/**
	 * 重新获取详情
	 */
	public AjaxResult findById(@PathVariable("id") Long id) {
		if (id == null) {
			return AjaxResult.getResult(Boolean.FALSE, "参数错误");
		}
		RemoveVO t = null;
		try {
			t = this.removeService.getInfo(id);
		} catch (XTBusinessException e) {
			e.printStackTrace();
			return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
		}
		return AjaxResult.getResult(t);
	}
	
}
